Skip to contentSkip to conversation

bitbake: toaster: Update filter count labels when Add/Remove layers

PATCH New Michael Wood 1 participant 1 message Oct 31, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bitbake: toaster: Update filter count labels when Add/Remove layers

When the user has added/removed a layer but no page reload/requery has happened we need to update the filter count labels client side.

[YOCTO #6861]

---
 bitbake/lib/toaster/toastergui/templates/filtersnippet.html |  4 ++--
 bitbake/lib/toaster/toastergui/templates/layers.html        | 13 +++++++++++++
 bitbake/lib/toaster/toastergui/templates/targets.html       | 10 ++++++++++
 3 files changed, 25 insertions(+), 2 deletions(-)
bitbake/lib/toaster/toastergui/templates/filtersnippet.html +2 -2
index 90ffd3d..fe70e71 100644
@@ -18,10 +18,10 @@
             {% for option in f.options %}
                 {% if option.2 %}
                     <label class="radio">
-                        <input type="radio" name="filter" {%if request.GET.filter == option.1 %}checked{%endif%}  value="{{option.1}}"> {{option.0}} ({{option.2}})
+                        <input type="radio" name="filter" {%if request.GET.filter == option.1 %}checked{%endif%}  value="{{option.1}}"> {{option.0}} (<span id="{{option.1}}_count">{{option.2}}</span>)
                 {% else %}
                     <label class="radio muted">
-                        <input type="radio" name="filter" disabled {%if request.GET.filter == option.1 %}checked{%endif%}  value="{{option.1}}"> {{option.0}} ({{option.2}})
+                        <input type="radio" name="filter" disabled {%if request.GET.filter == option.1 %}checked{%endif%}  value="{{option.1}}"> {{option.0}} (<span id="{{option.1}}_count">{{option.2}}</span>)
                 {% endif %}
                 {% if option.3 %}<i class="icon-question-sign get-help" data-placement="right" title="{{option.3}}"></i>{% endif %}
                 </label>
bitbake/lib/toaster/toastergui/templates/layers.html +13 -0
index 3dd2b1f..5227580 100644
@@ -121,10 +121,21 @@ function _makeXHREditCall(data, onsuccess, onfail) {
     });
 }
 
+function updateLayerCountLabels (amount) {
+    /* Update the filter labels */
+    var countLabel = $("#projectlayer__project\\:{{project.id}}_count");
+    countLabel.text(Number(countLabel.text())+amount);
+
+    var countLabelRemaining = $("#projectlayer__project\\:NOT{{project.id}}_count");
+    countLabelRemaining.text(Number(countLabelRemaining.text())-amount);
+}
+
 
 function layerDel(layerId, layerName, layerURL) {
     updatetext = "1 layer deleted";
     _makeXHREditCall({ 'layerDel': layerId }, function () {
+        updateLayerCountLabels(-1);
+
         show_alert("<strong>1</strong> layer deleted from <a href=\"{% url 'project' project.id%}\">{{project.name}}</a>: <a href=\""+layerURL+"\">" + layerName +"</a>");
     });
 }
@@ -188,6 +199,8 @@ function layerAdd(layerId, layerName, layerURL) {
                 if (_data.error != "ok") {
                     alert(_data.error);
                 } else {
+                    updateLayerCountLabels(_data.list.length+1);
+
                     if (_data.list.length > 0) {
                         show_dependencies_modal(layerId, layerName, layerURL, _data.list);
                     }
bitbake/lib/toaster/toastergui/templates/targets.html +10 -0
index 042d0fc..6b682bc 100644
@@ -182,6 +182,14 @@ function show_dependencies_modal(layerId, layerName, layerURL, dependencies) {
     $('#dependencies_modal').modal('show');
 }
 
+function updateLayerCountLabels (amount) {
+    /* Update the filter labels */
+    var countLabel = $("#layer_version__projectlayer__project\\:{{project.id}}_count");
+    countLabel.text(Number(countLabel.text())+amount);
+
+    var countLabelRemaining = $("#layer_version__projectlayer__project\\:NOT{{project.id}}_count");
+    countLabelRemaining.text(Number(countLabelRemaining.text())-amount);
+}
 
 function layerAdd(layerId, layerName, layerURL) {
     $.ajax({
@@ -191,6 +199,8 @@ function layerAdd(layerId, layerName, layerURL) {
                 if (_data.error != "ok") {
                     alert(_data.error);
                 } else {
+                    updateLayerCountLabels(_data.list.length+1);
+
                     if (_data.list.length > 0) {
                         show_dependencies_modal(layerId, layerName, layerURL, _data.list);
                     }
Signature · 1 line
1.9.1